// ==UserScript==
// @name       YE功能增强.03 - [随手记]
// @description  对随手记的网站进行了多项的增强。
// @copyright  2013+, AsionTang
// @namespace  http://AsionTang.CN
// @version    220611.20.05.041
// @iconURL    http://sui.com/favicon.ico
// @downloadURL https://gitee.com/AsionTang/52.ScriptLibrary/raw/master/YeJS/03.SuiShouJi.user.js
// @require     https://gitee.com/AsionTang/52.ScriptLibrary/raw/master/YeJS/00.Utils.js
// @require     https://gitee.com/AsionTang/52.ScriptLibrary/raw/master/YeJS/00.Utils.SuiShouJi.js
// @match      *://*.feidee.com/*
// @match      *://*.sui.com/*
// @run-at     document-end
// @grant none
// ==/UserScript==
var YeScript = YeScript || {};
//var YE_IS_DEBUG = true;

(function () {
    if (!isLocationHrefContainsAll('credit', 'indexmoney.do'))
        return;
    window.Ye_setIntervalId = setInterval(function () //
        {
            document.onclick = document_onclick;
            document_onclick();
        }, 1000);
    document.onclick = document_onclick;

    function document_onclick(e) //
    {
        //================================================================================
        console.log("21.支持自动跳转到指定文本高亮显示");
        //原因就是从滴答清单点击 #:~:text=XX卡 格式的网址跳转时,不能马上滚动到XX卡的位置
        //需要重新拖动网址到新的Tab页面才能滚动到XX卡的位置.所以这里做了一个特殊处理来实现
        //将滴答清单里的网址修改为 #text=XX卡 然后通过脚本替换为 #:~:text=XX卡 即可.
        //================================================================================
        location.hash=location.hash.replace('text=',':~:text=');

        //================================================================================
        console.log("20.信用卡中心 支持显示信用卡总额度2");
        //================================================================================

        var mTotalAmount = 0;
        function computeAll(items) //
        {
            for (var i = 0; i < items.length; i++) //
            {
                var item = items[i];
                mTotalAmount += Number.parseFloat(item.innerText);
            }
        }
        computeAll(document.querySelectorAll('.restLimit'));
        computeAll(document.querySelectorAll('.debtAmount'));

        console.log(mTotalAmount.toFixed(2));
        if (!document.getElementById('mTotalAmount')) //
        {
            var newDiv = document.createElement('div');
            newDiv.innerHTML = `<div class="topItems"><label id="mTotalAmount" class="topItems_t">总额度</label><span id="" class="topItems_b">${mTotalAmount.toFixed(2)}<span> 元</span></span></div>`;
            document.getElementById('cardNum').parentElement.parentElement.appendChild(newDiv);
        }

        //================================================================================
        console.log("19.信用卡中心 支持显示还款日到期提醒2");
        //================================================================================

        var items = document.querySelectorAll('.card_info tr:nth-child(1) > td:nth-child(2) > span');
        for (var i = 0; i < items.length; i++) //
        {
            var item = items[i];
            var time2 = new Date(obj2DateTime(item.innerText));

            //如果求的时间差为天数则处以864000000，如果是小时数则在这个数字上
            //除以24，分钟数则再除以60，依此类推
            var days = (time2.getTime() - Date.now()) / 86400000;
            if (isNaN(days))
                continue;
            item.innerHTML += '<span style="color:red;">(' + (parseInt(days) /*+ 1*/ ) + ')</span>';
        }

        clearInterval(window.Ye_setIntervalId);
    }
})();

(function () {
    if (window.location.pathname != '/tally/new.do')
        return;
    //================================================================
    // 18.快速记录网商贷款还款记录
    //================================================================
    {
        //将收债 修改为 还网商贷
        var btn = document.querySelector('#type-menu-ul > li:last-child > a');
        btn.innerText = '还网商贷';
        btn.onclick = function () {
            var msg = '';
            msg += '┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n';
            msg += '┃                                                              ┃\n';
            msg += '┃                        网商贷·还款中                        ┃\n';
            msg += '┃                                                              ┃\n';
            msg += '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n\n';
            msg += ' 待还款本金：请输入\n\n';
            msg += ' 待还款利息：请输入\n\n';
            msg += ' 可识别输入：本金 利息（用空格分割即可）\n\n';

            var defaultValue = '';
            var value = window.prompt(msg, defaultValue);
            if (!value) //
            {
                window.alert('已放弃还款!');
                return;
            }
            var items = value.split(' ');
            if (items.length != 2) //
            {
                window.alert('不可识别的输入格式!\n' + value);
                return;
            }
            var benJin = toNumber(items[0]);
            var liXi = toNumber(items[1]);
            var zongJieKuan;
            //当每月本机需要还款大于2000时,则是3W那笔借款
            if (benJin > 2000)
                zongJieKuan = '3W';
            else if (benJin > 1000)
                zongJieKuan = '1.25W';
            else //
            {
                window.alert('待还款本金输入有误!');
                return;
            }

            var memo = '网商贷；{总借款}；应还款；本金：{本金}；利息：{利息}；';
            memo = memo.replace('{总借款}', zongJieKuan);
            memo = memo.replace('{本金}', benJin);
            memo = memo.replace('{利息}', liXi);

            var time = new Date().toLocaleDateString().replace(/\//gm, '.') + ' ' + new Date().toTimeString().split(' ')[0];

            function transfer(out_account, in_account, price) //
            {
                var category = "0";
                var account = in_account + "-" + out_account;
                saveTransferRecord(category, account, price, time, memo);
            }
            //支付宝 - 网商贷:本金
            var out_account = '15416986541';
            var in_account = "2730294";
            var price = benJin;
            transfer(out_account, in_account, price);

            //支付宝 - 网商贷:利息
            var out_account = '15416986541';
            var in_account = "2730294";
            var price = liXi;
            transfer(out_account, in_account, price);

            //当每月本机需要还款大于2000时,则是3W那笔借款
            if (benJin > 2000) //
            {
                //假如是 3W那笔则需要将利息记录到老爸账上
                //网商贷 - 借给老爸
                var out_account = '2730294';
                var in_account = "27173940";
                var price = liXi;
                transfer(out_account, in_account, price);
            } else if (benJin > 1000) //
            {
                //假如是1.25W时,则需要额外记录
                //利息:网商贷 - 钱宝网
                var out_account = '2730294';
                var in_account = "15722972730";
                var price = liXi;
                transfer(out_account, in_account, price);

                //利息:钱宝网 负收入
                var category = "20515976212";
                var account = "15722972730";
                var price = liXi * -1;
                saveIncomeRecord(category, account, price, time, memo);
            } else //
            {
                window.alert('待还款本金输入有误!');
                return;
            }
        }
    }
})();

(function () {
    if (window.location.pathname != '/tally/new.do')
        return;
    //================================================================
    // 17.支持通过特定URL网址来实现添加收入记录的功能.
    //================================================================
    {
        /*var billType = {
        payout: 1,
        transferOut: 2,
        borrow: 3,
        borrowBack: 4,
        income: 5,
        lend: 6,
        lendBack: 7,
        transferIn: 8,
        daifu: 12
        };*/
        var bType;
        switch (location.search.substr(1)) {
            case "income":
                bType = billType.income;
                break;
            case "payout":
                bType = billType.payout;
                break;
            case "transfer":
                bType = billType.transferOut;
                break;
            default:
                return;
        }
        var args = location.hash.substr(1).split(',');
        var category = args[0];
        var price = args[2];
        var time = decodeURIComponent(args[3]);
        var memo = decodeURIComponent(args[4]);

        var account = 0;
        var in_account = 0;
        var out_account = 0;
        switch (location.search.substr(1)) {
            case "income":
            case "payout": {
                account = args[1];
            }
            break;
        case "transfer": {
            var as = args[1].split('-');
            in_account = as[0];
            out_account = as[1];
        }
        break;
        default:
            return;
        }

        //使用F12开发工具监听"添加收入记录"时的网络请求,从请求体里得到必要参数:account账户ID,category分类ID.
        var serverData = {
            //必要参数:
            price: price,
            time: time,
            memo: memo,
            account: account,
            category: category,
            //以下参数基本不变:
            debt_account: "",
            member: "0",
            in_account: in_account,
            out_account: out_account,
            price2: null,
            project: "0",
            store: "0",
            url: "",
            //debt是多余的,在网络请求时,没有此参数.
            debt: undefined
        }

        //opt = add，好像是用来控制界面消息显示的。listMsgShow用.
        billManager.data.dataPost(0, serverData, bType, "add");

        //自动关闭自动打开的网页.
        if (!YE_IS_DEBUG)
            setTimeout(function () {
                //Chrome浏览其中，关闭窗口js无效.(window.close()) - sunxuezhi322 - 博客频道 - CSDN.NET
                //http://blog.csdn.net/sxzlc/article/details/7588704
                window.open('', '_self', '');
                window.close();
            }, 1000);
    }
})();

(function () {
    if (window.location.pathname != '/tally/new.do')
        return;
    //================================================================
    // 16.检索条"选择时间"的开始时间默认为早一点的时间,以便检索"全部时间范围"
    //================================================================
    let isNeedAutoClick = false;

    //选择账户
    let zhStr = getQueryString('Accounts')
    if (zhStr) {
        let codes = [];
        let names = [];
        for (let f of zhStr.split(',')) {
            let code = getAccount(f);
            if (code) {
                codes.push(code);
                names.push(f);
            }
        }
        if (codes.length > 0) {
            tData.account = codes.join(",");
            let type = "account";
            tFilter.list.addOne(type, names);
            isNeedAutoClick = true;
        }
    }

    //选择分类
    let flStr = getQueryString('fenleis')
    if (flStr) {
        let codes = [];
        let names = [];
        for (let f of flStr.split(',')) {
            let code = getCategory(f);
            if (code) {
                codes.push(code);
                names.push(f);
            }
        }
        if (codes.length > 0) {
            tData.category = codes.join(",");
            let type = "category";
            tFilter.list.addOne(type, names);
            isNeedAutoClick = true;
        }
    }

    //搜索备注关键字
    let keyword = getQueryString('keyword')
    if (keyword) {
        document.getElementById('search-key').value = keyword;
        tData.keyword = keyword;
        tFilter.list.addKeyword(keyword);
        isNeedAutoClick = true;
    }
    //时间范围相关
    let searchTheOnlyOneDate = getQueryString('searchTheOnlyOneDate')
    if (searchTheOnlyOneDate) {
        document.getElementById('fb-begindate').value = searchTheOnlyOneDate;
        document.getElementById('fb-enddate').value = searchTheOnlyOneDate;
        isNeedAutoClick = true;
    } else {
        document.getElementById('fb-begindate').value = getQueryString('begindate') || "1992.01.01"
        document.getElementById('fb-enddate').value = getQueryString('enddate') || null;
    }
    //自动开始搜索
    if (isNeedAutoClick)
        setTimeout(() => {
            document.getElementById('fb-time-btn').click();
            //document.getElementById('search-btn').click();
        }, 1000);
})();
(function () {
    if (window.location.pathname != '/tally/new.do')
        return;
    //================================================================
    // 15.在所有可滚动的弹窗列表(如账户列表)滚动到底部时，不再触发整个页面的滚动！
    //================================================================
    var items = document.getElementsByClassName('w_select_box');
    for (var i = 0; i < items.length; i++) {
        var item = items[i];
        item.onmousewheel = function (e) {
            var item = e.srcElement.parentElement;
            //滚动到底部了.
            if (item.scrollTop + item.clientHeight == item.scrollHeight)
                if (e.deltaY > 0)
                    e.preventDefault();
        }
    }
})();
(function () {
    if (window.location.pathname != '/tally/new.do')
        return;
    document.onclick = function (e) {
        //================================================================
        // 14.列表编辑项的账户名排序,置顶功能.
        //================================================================
        console.log("触发账户排序,置顶事件.");
        var uls = document.querySelectorAll('.w_select_box');
        console.log("下拉框个数:" + uls.length);
        for (var i = 0; i < uls.length; i++) {
            var ul = uls[i];
            if (ul.id.toLowerCase().indexOf('account') == -1)
                continue;
            console.log("账户个数:" + ul.children.length);
            var ux = [];
            //循环提取时间，并调用排序方法进行排序
            for (var j = 0; j < ul.children.length; j++) {
                var li = ul.children[j];
                //
                var tmp = {};
                tmp.dom = li;
                tmp.title = li.title;
                //
                ux.push(tmp);
            }
            //数组排序，支持年的比较
            var topOneAccount = document.querySelector('#ul_tb-outAccount-1 .selected');
            if (topOneAccount != null)
                //[默认的置顶账户]：支出 - 账户
                topOneAccount = topOneAccount.innerText;
            else
                //[自定义置顶账户]：支出 - 金额（支持部分匹配置顶）
                topOneAccount = document.getElementById('tb-outMoney-1').value
            ux.sort(function (a, b) {
                //始终将用户选中的账户排序在最前!
                if (topOneAccount) {
                    if (a.title.indexOf(topOneAccount) > -1)
                        return -1;
                    if (b.title.indexOf(topOneAccount) > -1)
                        return 1;
                }
                return a.title.localeCompare(b.title) * 1;
                //*1是为了把字母开头的拍在前面.
            });
            //移除原先顺序错乱的li内容
            while (ul.firstChild)
                ul.removeChild(ul.firstChild);
            //再添加排序好的li内容
            for (var j = 0; j < ux.length; j++)
                $(ul).append(ux[j].dom);
        }
    }
})();
(function () {
    if (window.location.pathname != '/report/budget.jhtml')
        return;
    document.ondblclick = function () {
        //================================================================
        // 13.自动计算“截止今日的预算金额”
        //================================================================
        var tbOut = document.getElementById('tbOut');
        if (!tbOut)
            return;
        var items = tbOut.children;
        for (var i = 0; i < items.length; i++) {
            var tr = items[i];

            //获取“预算金额”标签
            var yusuanTD = tr.children[2];
            if (!yusuanTD)
                continue;
            yusuanTD.style.textAlign = 'right';
            yusuanTD.innerText += "　";
            yusuanTD.innerText = yusuanTD.innerText.replace('¥', '');

            //获取“实际金额”标签
            var shijiTD = tr.children[3];
            if (!shijiTD)
                continue;
            shijiTD.style.textAlign = 'right';
            shijiTD.innerText += "　";
            shijiTD.innerText = shijiTD.innerText.replace('¥', '');

            //获取“实际差额”标签
            var shijiChaYiTD = tr.children[4];
            if (!shijiChaYiTD)
                continue;
            shijiChaYiTD.style.textAlign = 'right';
            shijiChaYiTD.innerText = shijiChaYiTD.innerText.replace('¥', '');

            //获取“预算金额”
            var yusuanNumber = toNumber(yusuanTD.innerText);
            if (isNaN(yusuanNumber))
                continue;
            if (yusuanNumber <= 0) {
                yusuanTD.style.color = 'lightgray';
                continue;
            }

            //获取“实际金额”
            var shijiNumber = toNumber(shijiTD.innerText);
            if (isNaN(shijiNumber))
                continue;
            if (shijiNumber <= 0) {
                shijiTD.style.color = 'lightgray';
                continue;
            }

            var nowDate = new Date();
            var MaxDaysThisMonth = nowDate.getMonthDays();
            //当月最大天数
            var nowDay = nowDate.getDate();
            //今天几号

            //截止今日应该花掉的预算
            var nowYuSuan = yusuanNumber / MaxDaysThisMonth * nowDay;
            //与实际花掉的金额的差值
            var nowChaYi = shijiNumber - nowYuSuan;

            //当实际花得少时，不显示
            if (nowChaYi <= 0)
                continue;

            nowYuSuan = nowYuSuan.toFixed(2);
            nowChaYi = nowChaYi.toFixed(2);

            shijiTD.innerHTML = '<span style="text-align: left;float: left;">　' + nowYuSuan + '</span>' + shijiTD.innerText;

            shijiChaYiTD.innerHTML = '<span style="text-align: left;float: left;">　' + nowChaYi + '</span>' + shijiChaYiTD.innerText;
        }
        //document.ondblclick = null;
    };
})();

hideUnUseCard();

function hideUnUseCard() {
    if (window.location.pathname != '/credit/indexmoney.do')
        return;
    /*--------------------------------------------------------------------------------*/
    // 12.隐藏“不想看到的信用卡”
    /*--------------------------------------------------------------------------------*/
    $('#data_box_15654915883').hide();
    //中信
    $('#data_box_17006922813').hide();
    //虚拟信用卡
};
YeScript.showDailyWfsy = function () {
    /*--------------------------------------------------------------------------------*/
    // 11.添加“日万份收益”
    /*--------------------------------------------------------------------------------*/
    //取得“虚拟账户”的总金额
    var allElement = document.getElementById('ll-money-3');
    var allAmount = toNumber(allElement.innerText);

    //取得“投资账户”的总金额
    allElement = document.getElementById('ll-money-23');
    allAmount += toNumber(allElement.innerText);

    //日万份收益 = 总投资金额 * 10%（资产增长率）/ 365天
    var dailyWfsy = allAmount * 0.1 / 365;
    var mouthWfsy = dailyWfsy * 30;
    document.getElementById('jingzichan').parentElement.outerHTML += //
        '<li class=".l-list"><span class="lt-money-name" title="【“虚拟账户”+“投资账户”】">日收益：</span><span class="lt-money-num font-color-black" id="rishouyi">' //
        +
        dailyWfsy.toFixed(2).replace(/(\d)(?=(\d{3})+\.\d*$)/g, "$1,") //
        +
        '</span></li>' //
        +
        '<li class=".l-list"><span class="lt-money-name" title="【“虚拟账户”+“投资账户”】">月收益：</span><span class="lt-money-num font-color-black" id="rishouyi">' //
        +
        mouthWfsy.toFixed(2).replace(/(\d)(?=(\d{3})+\.\d*$)/g, "$1,") //
        +
        '</span></li>';
    document.getElementsByClassName('l-top')[0].style.background = 'url(../images/account/l_shadow_top.gif?1346920760000) right bottom no-repeat';
};
YeScript.quickShowAmount = function () {
    /*--------------------------------------------------------------------------------*/
    // 10.快速显示账户最新金额方便对账
    /*--------------------------------------------------------------------------------*/
    document.getElementById('tb-memo').value += "";
    document.getElementById('tb-memo').oncontextmenu = function (e) {
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4) {
                var obj = JSON.parse(xhr.responseText);
                var allAmoutInfo = "";
                //计算内容高度,然后好让显示的弹窗刚好是一屏的高度.
                var contentHeight = window.innerHeight - 66 - 70 - 20;
                //
                var msg = "";
                msg += "<div id='ye_quick_show_all_amount' style='margin-bottom: -34px;margin-top: -37px;height: " + contentHeight + "px;overflow-y: scroll;'>";
                msg += "<b>收入账户</b><hr>";
                msg += "<table width='100%'>";
                var items = obj.inlst;
                items.sort(function (a, b) {
                    //*1是为了把字母开头的拍在前面.
                    return a.name.localeCompare(b.name) * 1;
                });
                for (var i = 0; i < items.length; i++) {
                    var item = items[i];
                    if (item.amount == 0)
                        continue;
                    allAmoutInfo += item.name + item.symbol + item.amount;

                    msg += "<tr>"
                    msg += "<td width='50%' style='text-align: right;'>" + item.amount.toFixed(2) + "</td>"
                    //msg += "<td>　|　" + item.symbol + "</td>"
                    msg += "<td> | </td>"
                    msg += "<td style='text-align: left;'>" + item.name + "</td>"
                    msg += "</tr>";
                }
                msg += "</table>";
                msg += "<b>支出账户</b><hr>";
                msg += "<table width='100%'>";
                items = obj.outlst;
                items.sort(function (a, b) {
                    //*1是为了把字母开头的拍在前面.
                    return a.name.localeCompare(b.name) * 1;
                });
                for (var i = 0; i < items.length; i++) {
                    var item = items[i];
                    if (item.amount == 0)
                        continue;
                    allAmoutInfo += item.name + item.symbol + item.amount;

                    msg += "<tr>"
                    msg += "<td width='50%' style='text-align: right;'>" + item.amount.toFixed(2) + "</td>"
                    //msg += "<td>　|　" + item.symbol + "</td>"
                    msg += "<td> | </td>"
                    msg += "<td style='text-align: left;'>" + item.name + "</td>"
                    msg += "</tr>";
                }
                msg += "</table>";
                msg += "</div>";

                $.confirmInfo(msg, '账户金额', function () {});

                //滚动到底部时,不会触发外层滚动条.
                document.getElementById('ye_quick_show_all_amount').onmousewheel = function (e) {
                    var item = document.getElementById('ye_quick_show_all_amount');
                    //滚动到底部了.
                    if (item.scrollTop + item.clientHeight == item.scrollHeight)
                        if (e.deltaY > 0)
                            e.preventDefault();
                }

                //记录所有账户与对应的金额以便对账时能存储一个"快照状态".
                console.log(allAmoutInfo);
                document.getElementById('ye_quick_show_all_amount').ondblclick = function () {
                    var tipTitle = "";
                    tipTitle += '┏━━━━━━━━━━━━━━━━━━━━━━━━┓\n';
                    tipTitle += '┃使用 Ctrl + C 复制 即可！           By:AsionTang┃\n';
                    tipTitle += '┗━━━━━━━━━━━━━━━━━━━━━━━━┛';
                    window.prompt(tipTitle, allAmoutInfo);
                }
            }
        }
        xhr.open("GET", "https://www.sui.com/report.rmi?m=asset", true);
        xhr.send();
        return false;
    }
}
YeScript.exShowIconName = function () {
    /*--------------------------------------------------------------------------------*/
    // 9.显示分类图标名称
    /*--------------------------------------------------------------------------------*/
    var items = document.getElementsByClassName('cat32');
    for (var i = 0; i < items.length; i++) {
        items[i].innerText = items[i].title;
        items[i].style.paddingTop = '32px';
    }
    var items = $('.popup_model ul.u3 .l2 a span');
    //var items = document.getElementsByClassName('.popup_model ul.u3 .l2 a span')
    for (var i = 0; i < items.length; i++)
        items[i].style.height = '64px';
    console.info('9:ok');
};
YeScript.exReport = function () {
    /*--------------------------------------------------------------------------------*/
    // 8.“日常收支表”点击内容在新窗口查看
    /*--------------------------------------------------------------------------------*/
    document.onclick = function () {
        var uls = document.getElementsByTagName('ul');
        for (var i = 0; i < uls.length; i++) {
            var ul = uls.item(i);
            if (ul.onclick == null || ul.onclick.toString().indexOf('go(') == -1)
                continue;
            var funcGo = ul.onclick.toString();
            var id = funcGo.slice(funcGo.lastIndexOf('(') + 1, funcGo.lastIndexOf(')'));
            var url = 'var url=\'tally/new.do?cid=' + id + '&amp;beginDate=\'+tData.startTime+\'&amp;endDate=\'+tData.endTime;';
            // event.stopImmediatePropagation();可以马上阻止事件传播！
            ul.innerHTML = '<div onclick="event.stopImmediatePropagation();' + url + 'window.open(url);">' + ul.innerHTML + '</div>';
        }
        console.info('8:ok');
    };
};
YeScript.exAccount = function () {
    /*--------------------------------------------------------------------------------*/
    // 7.添加“可动产”
    /*--------------------------------------------------------------------------------*/
    var jzcEle = document.getElementById('jingzichan');
    var jinzichan = jzcEle.innerText.replace(',', '');
    var xianjinliu = jinzichan - document.getElementById('ll-money-15').innerText.replace(',', '');

    //日万份收益 = 总投资金额 * 3%（资产增长率）/ 365天
    var dailyWfsy = xianjinliu * 0.03 / 365;
    var mouthWfsy = dailyWfsy * 30;
    document.getElementById('jingzichan').parentElement.outerHTML +=
        '<li class=".l-list"><span class="lt-money-name" title="【现在可动的资产 = 净资产 - 债权】">可动产：</span><span class="lt-money-num font-color-black" id="xianjinliu">' 
        + xianjinliu.toFixed(2).replace(/(\d)(?=(\d{3})+\.\d*$)/g, "$1,") +
        '</span></li>' + '<li class=".l-list"><span class="lt-money-name" title="【“虚拟账户”+“投资账户”】">可动产3%日收益：</span><span class="lt-money-num font-color-black" id="rishouyi">' //
        +
        dailyWfsy.toFixed(2).replace(/(\d)(?=(\d{3})+\.\d*$)/g, "$1,") //
        +
        '</span></li>' //
        +
        '<li class=".l-list"><span class="lt-money-name" title="【“虚拟账户”+“投资账户”】">可动产3%月收益：</span><span class="lt-money-num font-color-black" id="rishouyi">' //
        +
        mouthWfsy.toFixed(2).replace(/(\d)(?=(\d{3})+\.\d*$)/g, "$1,") //
        +
        '</span></li>';

    document.getElementsByClassName('l-top')[0].style.background = 'url(../images/account/l_shadow_top.gif?1346920760000) right bottom no-repeat';
    console.info('7:ok');
};
YeScript.exNew = function () {
    /*--------------------------------------------------------------------------------*/
    // 6.修改已添加项的备注时，Enter自动保存！折叠！
    /*--------------------------------------------------------------------------------*/
    window.oldClearDefaultMemo = window.clearDefaultMemo;
    window.clearDefaultMemo = function (obj) {
        console.info('6.0:ok');
        window.oldClearDefaultMemo(obj);
        $(obj).keydown(function (e) {
            console.info('6.1:ok');
            if (e.keyCode != 13)
                return;
            var id = window.tList.box.currentOpen;
            console.log(id);
            if (!tList.box.data[id])
                return;
            var type = window.tList.box.data[id][1].tranType;
            window.billManager.data.save(id, type);
        });
    };
    /*--------------------------------------------------------------------------------*/
    // 5.展开折叠时，焦点自动定位到备注输入框！并全选文本！
    /*--------------------------------------------------------------------------------*/
    //随手记升级到新版UI后,此功能无效.留待以后有精力后再恢复.
    //window.data = window.tList.box.data;
    //window.oldLoadBox = window.tList.box.loadBox;
    //window.tList.box.loadBox = function(id) {
    //    console.info('5:ok');
    //    window.oldLoadBox(id);
    //    var memo = $("#list-box-" + id + " input[name='list-memo']");
    //    memo.focus();
    //    memo.select();
    //};
    /*--------------------------------------------------------------------------------*/
    // 4.金额输入框，清空 0.00
    /*--------------------------------------------------------------------------------*/
    $(".input.money").focus(function (e) {
        console.info('4:ok');
        if (e.currentTarget.value == "0.00")
            e.currentTarget.value = null;
    });
    /*--------------------------------------------------------------------------------*/
    // 3.备注输入框，Enter变Tab键。
    /*--------------------------------------------------------------------------------*/
    $("#tb-memo").keydown(function (e) {
        console.info('3:ok');
        if (e.keyCode != 13)
            return;
        var evt = document.createEvent("KeyboardEvent");
        evt.initKeyboardEvent("keydown", true, true, window, "U+0009", 0, false, false, true, false, false);
        e.currentTarget.dispatchEvent(evt);
        window.billManager.data.add();
    });
    /*--------------------------------------------------------------------------------*/
    // 2.金额输入框，Enter变Tab键。
    /*--------------------------------------------------------------------------------*/
    $(".input.money").keydown(function (e) {
        console.info('2:ok');
        if (e.keyCode != 13)
            return;
        e.stopPropagation();
        // 取消冒泡
        e.preventDefault();
        // 取消浏览器默认行为
        var evt = document.createEvent("KeyboardEvent");
        evt.initKeyboardEvent("keydown", true, true, window, "U+0009", 0, false, false, false, false, false);
        e.currentTarget.dispatchEvent(evt);
    });
    /*--------------------------------------------------------------------------------*/
    // 1.设置Tab顺序，金额的下一个就跳到备注
    /*--------------------------------------------------------------------------------*/
    $(".input.money").attr("tabindex", 1);
    $("#tb-memo").attr("tabindex", 2);
    console.info('1:ok');
};

switch (window.location.pathname) {
    case "/tally/new.do":
        inject(YeScript.exNew);
        inject(YeScript.quickShowAmount);
        break;
    case "/account/account.do":
        inject(YeScript.showDailyWfsy);
        inject(YeScript.exAccount);
        break;
    case "/report.shtml":
        inject(YeScript.exReport);
        break;
    case "/category/budgetCategory.do":
        inject(YeScript.exShowIconName);
        break;
}

function getQueryString(name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'); //再尝试不区分大小写的方式匹配.
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return decodeURIComponent(r[2]);
    }
    return null;
}